package com.aaa.service.impl.scl;

import com.aaa.entity.MyPage;
import com.aaa.entity.User;
import com.aaa.entity.scl.TsclPlan;
import com.aaa.entity.scl.TsclQuestion;
import com.aaa.mapper.scl.TsclPlanMapper;
import com.aaa.service.scl.TsclPlanService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;


@Service
public class TsclPlanServiceImpl implements TsclPlanService {
    @Autowired
    private TsclPlanMapper tsclPlanMapper;

    /**
     * 查询计划页面
     */
    @Override
    public PageInfo selectAll(MyPage myPage,TsclPlan tsclPlan) {
        PageHelper.startPage(myPage.getPage(),myPage.getLimit());
        List<TsclPlan> userList = tsclPlanMapper.queryAll();
        PageInfo pageInfo = new PageInfo(userList);
        return pageInfo;
    }


    /**
     * 添加计划
     */
    @Override
    public boolean insertPlan(TsclPlan tsclPlan) {

        System.out.println("tsclPlan ---------------= " + tsclPlan);
        int i = -1;
        Integer id = tsclPlan.getId();
        if(id==null){
            tsclPlan.setCreatetime(new Date());
            i = tsclPlanMapper.insert(tsclPlan);

        }else {
            tsclPlan.setUpdatetime(new Date());
            i = tsclPlanMapper.updateByPrimaryKeySelective(tsclPlan);
        }
        return i>=0;
    }

    /**
     * 修改状态
     */
    @Override
    public boolean updatastatus(TsclPlan tsclPlan) {
        int i = tsclPlanMapper.updateByPrimaryKeySelective(tsclPlan);
        return  i>0?true:false;
    }


    /**
     * 检测验证码是否存在
     */
     @Override
    public Boolean checkcode(TsclPlan tsclPlan) {
         TsclPlan tsclPlan1 = tsclPlanMapper.selectOne(tsclPlan);
         if(tsclPlan1!=null){
            return true;
         }else {
            return false;
         }

    }

    /**
     * 检测计划名称是否存在
     * @param planname
     * @return
     */
    @Override
    public Boolean checkPlanname(String planname) {
        TsclPlan tsclPlan = new TsclPlan();
        tsclPlan.setPlanname(planname);
        TsclPlan tsclPlan1 = tsclPlanMapper.selectOne(tsclPlan);
        if(tsclPlan1!=null){
            return true;
        }else {
            return false;
        }
    }

}
